﻿using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Routing;

namespace Wechat.API
{
    public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            GlobalConfiguration.Configure(WebApiConfig.Register);

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);

            //初始化AutoFac
            AutoFacBootStrapper.CoreAutoFacInit();

            //初始化Log4Net
            log4net.Config.XmlConfigurator.Configure();

            //初始化AutoMapper
            AutoMapperBooStrapper.RegisterMaps();

            //清除XML序列化，只需要JSON序列化
            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();

            //设置JSON序列化方式-驼峰命名
            HttpConfiguration config = GlobalConfiguration.Configuration;
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            config.Formatters.JsonFormatter.UseDataContractJsonSerializer = false;

            GlobalConfiguration.Configuration.EnsureInitialized();
        }
    }
}
